﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using WebUI.Primitives;

namespace WebUI
{
    public class Composition
    {
        public void Init()
        {
            var container = new CompositionContainer( new DirectoryCatalog(HostingEnvironment.MapPath("~/bin")));

            CompositionBatch batch = new CompositionBatch();

            batch.AddPart(this);

            ControllerBuilder.Current.SetControllerFactory(new MEFControllerFactory(container));

            System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new MefDependencyResolver(container);

            container.Compose(batch);
        }
    }
}